package com.itheima.tlias84.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.tlias84.dto.SelectLearnerDTO;
import com.itheima.tlias84.dto.SelectLearnerDetailDTO;
import com.itheima.tlias84.mapper.LearnerMapper;
import com.itheima.tlias84.po.InsertLearnerParam;
import com.itheima.tlias84.po.SelectLearnerPageParam;
import com.itheima.tlias84.po.UpdateLearnerParam;
import com.itheima.tlias84.service.LearnerService;
import com.itheima.tlias84.utils.ResultUtil;
import com.itheima.tlias84.vo.PageVO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LearnerServiceImpl implements LearnerService {
    @Resource
    LearnerMapper learnerMapper;
    @Override
    public ResultUtil selectLearnerByPage(SelectLearnerPageParam param) {
        Page<Object> page = PageHelper.startPage(param.getPage(), param.getPageSize());
        List<SelectLearnerDTO> dtos = learnerMapper.selectLearnerByPage(param);
        PageVO<SelectLearnerDTO> pageVO = new PageVO<>();
        pageVO.setTotal(page.getTotal());
        pageVO.setRows(dtos);
        return ResultUtil.success(pageVO);
    }

    @Override
    public int insertLearner(InsertLearnerParam param) {
        int flag = learnerMapper.insertLearner(param);
        return flag;
    }
    //根据id查询
    @Override
    public SelectLearnerDetailDTO selectLearnerById(Integer id) {
        SelectLearnerDetailDTO dto = learnerMapper.selectLearnerById(id);
        return dto;
    }

    @Override
    public int updateLearner(UpdateLearnerParam param) {
        int flag = learnerMapper.updateLearner(param);
        return flag;
    }

    @Override
    public int batchDeleteLearnerByIds(List<Integer> ids) {
        int flag = learnerMapper.batchDeleteLearnerByIds(ids);
        return flag;
    }

    @Override
    public int vioScore(Integer id, Integer score) {
        int flag = learnerMapper.vioScore(id, score);
        return flag;
    }

}
